<%--
  Created by IntelliJ IDEA.
  User: SkiMei
  Date: 2021/6/29
  Time: 8:40
  To change this template use File | Settings | File Templates.
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<div>
    <a href="<%=request.getContextPath()%>/user/logout">退出</a>
</div>
<div>
    <img id="avater" alt="" width="200px" height="200px" src="/img/1.jpg"/>
    <input type="file" onchange="onSelectImage(this)">
</div>
<c:forEach items="${userList}" var="item">
    ${item.nickname}
</c:forEach>
<script>
    function onSelectImage(e){
        var file = e.files[0];
        var formData = new FormData();
        formData.append("file",file);
        $.ajax({
            url:'<%=request.getContextPath()%>/user/upload',
            type:'post',
            data:formData,
            contentType:false,
            processData:false,
            success(res){
                if (res.success){
                    $("#avater").attr("src",res.data);
                }
            }
        })
    }
</script>
</body>
</html>
